Linux Terminal Command Reference

Alexio
  7 years ago
  359

System Info

date – Show the current date and time
cal – Show this month's calendar
uptime – Show current uptime
w – Display who is online
whoami – Who you are logged in as
finger user – Display information about user
uname -a – Show kernel information
cat /proc/cpuinfo – CPU information
cat /proc/meminfo – Memory information
df -h – Show disk usage
du – Show directory space usage
free – Show memory and swap usage

Keyboard Shortcuts

Enter – Run the command
Up Arrow – Show the previous command
Ctrl + R – Allows you to type a part of the command you're looking for and finds it

Ctrl + Z – Stops the current command, resume with fg in the foreground or bg in the background
Ctrl + C – Halts the current command, cancel the current operation and/or start with a fresh new line
Ctrl + L – Clear the screen

command | less – Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow
!! – Repeats the last command
command  !$ – Repeats the last argument of the previous command
Esc + . (a period) – Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command

Ctrl + A – Return to the start of the command you're typing
Ctrl + E – Go to the end of the command you're typing
Ctrl + U – Cut everything before the cursor to a special clipboard, erases the whole line
Ctrl + K – Cut everything after the cursor to a special clipboard
Ctrl + Y – Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to
Ctrl + T – Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)
Ctrl + W – Delete the word / argument left of the cursor in the current line

Ctrl + D – Log out of current session, similar to exit

Learn the Commands

apropos subject – List manual pages for subject
man -k keyword – Display man pages containing keyword
man command – Show the manual for command
man -t man | ps2pdf - > man.pdf  – Make a pdf of a manual page
which command – Show full path name of command
time command – See how long a command takes

whereis app – Show possible locations of app
which app – Show which app will be run by default; it shows the full path

Searching

grep pattern files – Search for pattern in files
grep -r pattern dir – Search recursively for pattern in dir
command | grep pattern – Search for pattern in the output of command
locate file – Find all instances of file
find / -name filename – Starting with the root directory, look for the file called filename
find / -name ”*filename*” – Starting with the root directory, look for the file containing the string filename
locate filename – Find a file called filename using the locate command; this assumes you have already used the command updatedb (see next)
updatedb – Create or update the database of files on all file systems attached to the Linux root directory
which filename – Show the subdirectory containing the executable file  called filename
grep TextStringToFind /dir – Starting with the directory called dir, look for and list all files containing TextStringToFind

File Permissions

chmod octal file – Change the permissions of file to octal, which can be found separately for user, group, and world by adding: 4 – read (r), 2 – write (w), 1 – execute (x)
Examples:
chmod 777 – read, write, execute for all
chmod 755 – rwx for owner, rx for group and world
For more options, see man chmod.

File Commands

ls – Directory listing
ls -l – List files in current directory using long format
ls -laC – List all files in current directory in long format and display in columns
ls -F – List files in current directory and indicate the file type
ls -al – Formatted listing with hidden files

cd dir – Change directory to dir
cd – Change to home
mkdir dir – Create a directory dir
pwd – Show current directory

rm name – Remove a file or directory called name
rm -r dir – Delete directory dir
rm -f file – Force remove file
rm -rf dir – Force remove an entire directory dir and all it’s included files and subdirectories (use with extreme caution)

cp file1 file2 – Copy file1 to file2
cp -r dir1 dir2 – Copy dir1 to dir2; create dir2 if it doesn't exist
cp file /home/dirname – Copy the filename called file to the /home/dirname directory

mv file /home/dirname – Move the file called filename to the /home/dirname directory
mv file1 file2 – Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directory file2

ln -s file link – Create symbolic link link to file
touch file – Create or update file
cat > file – Places standard input into file
cat file – Display the file called file

more file – Display the file called file one page at a time, proceed to next page using the spacebar
head file – Output the first 10 lines of file
head -20 file – Display the first 20 lines of the file called file
tail file – Output the last 10 lines of file
tail -20 file – Display the last 20 lines of the file called file
tail -f file – Output the contents of file as it grows, starting with the last 10 lines

Compression

tar cf file.tar files – Create a tar named file.tar containing files
tar xf file.tar – Extract the files from file.tar

tar czf file.tar.gz files – Create a tar with Gzip compression
tar xzf file.tar.gz – Extract a tar using Gzip

tar cjf file.tar.bz2 – Create a tar with Bzip2 compression
tar xjf file.tar.bz2 – Extract a tar using Bzip2

gzip file – Compresses file and renames it to file.gz
gzip -d file.gz – Decompresses file.gz back to file

Printing

/etc/rc.d/init.d/lpd start – Start the print daemon
/etc/rc.d/init.d/lpd stop – Stop the print daemon
/etc/rc.d/init.d/lpd status – Display status of the print daemon
lpq – Display jobs in print queue
lprm – Remove jobs from queue
lpr – Print a file
lpc – Printer control tool
man subject | lpr – Print the manual page called subject as plain text
man -t subject | lpr – Print the manual page called subject as Postscript output
printtool – Start X printer setup interface

Network

ifconfig – List IP addresses for all devices on the local machine
iwconfig – Used to set the parameters of the network interface which are specific to the wireless operation (for example: the frequency)
iwlist – used to display some additional information from a wireless network interface that is not displayed by iwconfig
ping host – Ping host and output results
whois domain – Get whois information for domain
dig domain – Get DNS information for domain
dig -x host – Reverse lookup host
wget file – Download file
wget -c file – Continue a stopped download

SSH

ssh user@host – Connect to host as user
ssh -p port user@host – Connect to host on port port as user
ssh-copy-id user@host – Add your key to host for user to enable a keyed or passwordless login

User Administration

adduser accountname – Create a new user call accountname
passwd accountname – Give accountname a new password
su – Log in as superuser from current login
exit – Stop being superuser and revert to normal user

Process Management

ps – Display your currently active processes
top – Display all running processes
kill pid – Kill process id pid
killall proc – Kill all processes named proc (use with extreme caution)
bg – Lists stopped or background jobs; resume a stopped job in the background
fg – Brings the most recent job to foreground
fg n – Brings job n to the foreground

Installation from source

./configure
make
make install
dpkg -i pkg.deb – install a DEB package (Debian / Ubuntu / Linux Mint)
rpm -Uvh pkg.rpm – install a RPM package (Red Hat / Fedora)

Stopping & Starting

shutdown -h now – Shutdown the system now and do not reboot
halt – Stop all processes - same as above
shutdown -r 5 – Shutdown the system in 5 minutes and reboot
shutdown -r now – Shutdown the system now and reboot
reboot – Stop all processes and then reboot - same as above
startx – Start the X system

Recommended reading:

Cheat-Sheets.org – All cheat sheets, round-ups, quick reference cards, quick reference guides and quick reference sheets in one page. The only one you need.

Tutorial: The best tips & tricks for bash, explained – Linux Tutorial Blog / Quality Linux tutorials without clutter

LinuxCommand.org – Learning the shell, Writing shell scripts, Script library, SuperMan pages, Who, What, Where, Why

LinuxManPages.com – General commands, System calls, Subroutines, Special files, File formats, Games, Macros and conventions, Maintenence commands, Most Popular Man Pages

Linux Man Pages from die.net – Man pages are grouped into sections, to see the full list of Linux man pages for a section, pick one. Or you can browse Linux man pages by name; choose the first letter of the name of the Linux command, function, or file you are interested in.

Linux Newbie Guide: Shorcuts and Commands – Linux essential shortcuts and sanity commands; Common Linux commands - system info; Basic operations, network apps, file (de)compression; Process control; Basic administration commands, accessing drives/partitions; Network administration tools, music-related commands, graphics-related commands.

Sudo Manual Pages – Sudo (su "do") allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments. For more information, see the introduction to Sudo. Sudo is free software, distributed under an ISC-style license.

LinOxide.com – Linux Commands Cheat Sheet in Black & White

Comments
adamsnumber1 1 year ago

grate way for a noob to linux like me to learn thanks


Bodmin 2 years ago

Awesome tutorial! One trick I started doing with so many helpful webpages out there is highlighting code to put in a terminal, right-clicking and choosing copy then right-clicking on the terminal cursor and choosing paste. It's not that I hate to type, but doing this solves the inevitable spelling errors. Thank you for your work Alexio in putting this page together.


johnsageek 2 years ago

That is a great newbie ref guide. Good thing


BenjaminL 4 years ago

Thank you, this is very useful !


busdriver12 4 years ago

You never stop learning - thanks very much!


wdinspi 4 years ago

Wow !! great


cristiandechiara 4 years ago

alias command??


Eddy 4 years ago

Very useful


jfe58 4 years ago

Thank you so much!

Signed a Linux Mint newbie.


Machpitt 5 years ago

Muito bom! Parabéns!!!


Poetician 5 years ago

Very handy and much appreciated. Thank you


greencedar 5 years ago

Very useful. Thank you.


druatmint 5 years ago

thanks a lot this page helps me so much to use linux.


Midget0020 6 years ago

yes Very helpful. Thanks.


vozmischev 6 years ago

thanks, very useful


guitarlayton 6 years ago

Excellent very useful


kap_cool 7 years ago

very helpfulll....


Alhadi2000 7 years ago

thanks ..excellent and helpful info


geroot 7 years ago

Thanks for that. i save that.


semiramida 8 years ago

very helpfull for newbie , tnx


ittechspark 8 years ago

Great...


aRMY 8 years ago

Great Tutorials


Tookie 8 years ago

Excellent. Just what I needed, all info in one place. Thank you.


Rouler 8 years ago

Muy buen aporte, a muchos les servirá bastante...


tejash 8 years ago

તમે આ માહિતી માટે ખૂબ આભાર, મારા એક મોટી સમસ્યા આદેશ વાક્ય સ્વીચો તમામ છે અને ઉચ્ચ અથવા નિમ્ન કિસ્સામાં ત્યાં અને / જ સંદર્ભમાં છે આદેશો દરેક માટે અર્થ જો. પણ નવા કાર્યક્રમો સ્થાપન .ડેબ .SH (કોમ્પ્રેસ્ડ tar.bz/bz2 GZ) ચલાવો.
ઓકે દેબ સોફ્ટવેર સેન્ટર પરંતુ બાકીના શું નાઇટમેર સાથે ખોલે છે.
મહાન ટ્યુટોરીયલ અને ખૂબ જ ઉપયોગી


JosueC 8 years ago

I need it.


rrivera 8 years ago

thanks! very useful to newbes like me


danurahmat 8 years ago

Very helpful tutorial! Thanks


aplatypus 9 years ago

Essential reading.


tom3143 9 years ago

Great reference. Thanks


musicinhills 9 years ago

Thank you for taking the time to teach others, this is a great big help to me. So thanks once again very very much appreciated
Kind regards
musicinhills


nicholas_01 9 years ago

Well done! Tahnk you!!


Old_Curmudgeon 9 years ago

Very well done!
Thanks a million!


paul2carter 9 years ago

type in terminal the line below and you will find you're distro flavor/info

lsb_release -a

No LSB modules are available.
Distributor ID: LinuxMint
Description: Linux Mint 17.2 Rafaela
Release: 17.2
Codename: rafaela


MagicMint 9 years ago

A good reference.


subho 9 years ago

good one


paul2carter 9 years ago

very informative


SpeedyGonzalez 9 years ago

very very interesting. thank you


DINHO 9 years ago

I am new with Linux Mint... this your tutorial is cool and minimal soft...


Oswald77 9 years ago

Very helpful, thank you very much.


808Souljah 9 years ago

I cheat all the time


Yarus-Arsene 9 years ago

thanks for the nice tutorial..


zantaz 9 years ago

little mistake: the tutorial is wrote by @alexio. Good wise guy ...


zantaz 9 years ago

Another good tutorial by @clem. Go straigth foward !


fodder 9 years ago

Thank you for this so, so much. I was (Am) a noob in need, and this saved me. ;) Google is okay, but THIS is what I was looking for!


kyriakos77 9 years ago

Thanks! Very nice stuff.


aldy 9 years ago

Very helpful, keep me going for ages, thanks. A newbie


lib2know 9 years ago

common information, but here more compressed and more complete than elsewhere. Very helpful, thanks!


sidsingh 9 years ago

Thanks! Very nice information, Especially for beginners.


rgucluer 10 years ago

Thank you. Necessary information combined. Helpful for newcomers like me.


Spearmint 10 years ago

It would be good to add some disk commands like

blkid
fdisk
parted
lsblk
df
although I'd not add gdisk till this msg is corrected;

"Found invalid GPT and valid MBR; converting MBR to GPT format
in memory."

since it doesn't change the MBR unless specifically instructed to.


chriselk 10 years ago

Can anyone explain how to remove the annoying authorise box popup every time i want to access a location, such as installing software for example. i am using Mint 17 Cinnamon.


chriselk 10 years ago

Very good and informative.


kristall1971 10 years ago

thanks


screaming-goat 10 years ago

Great info! Also thanks for the Recommended reading section much needed as well! Thanks much!!


Johnfromct 10 years ago

This is very helpful. I love this site. Thanks for all the info.


Gannet 10 years ago

Very useful. We need something like this aimed specifically at XP refugees. Do you know of one?


Alexio 10 years ago

@breaker - Thank you so much for your suggestions! Just added the "Linux Man Pages from die.net" link to the "Recommended reading".


Alexio 10 years ago

@fuLLcoLLapse & @breaker - I added the "Sudo Manual Pages" link to the "Recommended reading" section.


Alexio 10 years ago

@linux_commands & @jfleen - The website LinuxCommand.net is no longer available...


Alexio 10 years ago

@lib2know - Thank you very much! The commands are now listed in the "Network" section.


Alexio 10 years ago

@gangmei - Thank you for the correction!


lib2know 10 years ago

Great work!
Important but missing is iwconfig and iwlist in the network section.


blew10 10 years ago

Great really liked it..


netopyr 10 years ago

Thanks for this very good work!


melsevier 10 years ago

I suggested this and was told that it was a stupid, and definitely was not an idea! I am glad to see someone finally created it. This is awesome! Thank You So Much!!!


Datei 10 years ago

love it !!!


jfleen 10 years ago

Love this. Thank you so much. Also, thanks to linux_commands for the reference at http://www.linuxcommand.net

Man, I love this community.


ericvictor66 10 years ago

Very usefull, thank you!


Thejan 10 years ago

This is very helpful. Thanks.


jahid_0903014 10 years ago

thanks


CodieLM 11 years ago

useful resource, thanks!


Thejan 11 years ago

This is very useful and thank you so much. This was a my major problem when I going to work - specially when I going to install software..... Again Thank you very much.


sujitnag 11 years ago

short and nice.


soconn 11 years ago

this is a great resource!


Tux909 11 years ago

nice tut


xud00bux 12 years ago

fantastic for a beginner! Thx


piyush 12 years ago

thank you


Thinker 12 years ago

Nice Guide. Thanks


roht 12 years ago

very handy.


dazw2000 12 years ago

Thank you so much for this information, my one major problem is all of the command line switches and if there in upper or lower case and are of the same context/meaning for each of the commands. Also the installation of new applications .deb .sh (compressed tar.bz/bz2 gz) .run.
Ok deb opens with the software center but the rest what a nightmare.
Great tutorial and very helpful


konasteph 12 years ago

Thanks for doing this for all of us. This helps to make linux mint a true community effort ..Thanks to this and other tutorials I got to where I am, using LMDE as my platform, and I am no longer looking for this sort of info as much as in the beginning. But that is exactly the point: These tutorials helped me and others to reach this point, where we use LM and its all working for us!!


arnshahz 12 years ago

hi...

im newbie and slow learner... tq for the tutorial... need to know basic command line and willin to learn...


joroxrd 12 years ago

Thank you!


kututech 12 years ago

Thanks a lot, this very helpful


davey1986 12 years ago

Thank you, this is very useful!!!


jerincon 12 years ago

Tks! Very useful reference... to bmrks!


konasteph 13 years ago

thanks greatly bing search finds this article quickly...respectable.


sunewbie 13 years ago

Thank you, very useful.


Anleoje 13 years ago

Thank you :)


Labby 13 years ago

This will come in handy for sure! Promoted and subscribed.


WillemUK 13 years ago

Great tutorial for learning terminal commands.
Checking back here when i am stuck or want to try out something.


gingembre 13 years ago

Thanks, alexio... May I translate that in french for some users ?


breaker 13 years ago

Nice list. I have used most of these, and I have to say for the most part, the man pages are the most helpful. Let me suggest a couple others (I use these often);

sudo and gksudo - run something as a superuser (cli and gui)

NOTE: add an ampersand after a command to have it run in the background and return the shell to the user, example "gksudo gedit [filename] &"

history - this gives you a numbered list off all previously typed commands, then to repeat one of the commands just enter !123 or whatever number it is. Goes along with !! and up arrow key...

less [filename] - From man page - less is a program similar to more (1), but which allows backward movement in the file as well as forward movement.Also, less does not have to read the entire input file before starting.

nano - simple text editor in the terminal (easier than vi or emacs)

mount - mount something somewhere, very handy...

dmesg - get system messages, stuff like "dmesg |tail" helps after inserting a usb device such as a flash drive to see what's up with it

nslookup - query Internet name servers interactively

keyboard shortcut to switch terminals - CTRL+ALT+F1 thru F7, F7 is your normal GUI tty7, but in case you need a full-screen terminal you can switch and login to F1, F2, etc

apt version [package] - see the version of an installed package

for df, I suggest "df -h" it makes it more human readable

md5sum - print or check md5sums (man md5sum), also sha1sum, etc.

"sudo fdisk -l" lists the partition tables for all of your devices then exits

chown - change ownership of a file, sometimes helpful

See the new Tron? It was cool how they used whoami and ps axu and stuff.

Remember the TRS-80/DOS command tron? A debugging command it means trace on, troff turns it off.

Get linux man pages in a nice web browser format by visiting http://linux.die.net/man/


trollboy 13 years ago

Nice tutorial, but when compiling from source, yo should read the supplied readme file as it is almost but not quite always as simple as configure, make, make install


DJ_KIM 13 years ago

ok, what would I use to get it to find trackers


Alexio 13 years ago

@DJ_KIM - You should use the command

sudo avgctl

and not sudo-avgctl.

Anyway, just follow all the steps from the tutorial posted at http://www.ihaveapc.com/2011/07/how-to-install-and-use-avg-antivirus-in-linux-mint-ubuntu/


DJ_KIM 13 years ago

I downloaded both the deb and the tar files, because I wasn't sure which one to use, as some programs use tar and others use deb. When I try to install it again, it says already installed and asks if I want to re-install, which I tell it yes.

I also tried it without the dash between sudo and avgctl, and it still told me not found.


DJ_KIM 13 years ago

I did the sudo-avgctl in the terminal and it says not found


Alexio 13 years ago

@DJ_KIM - After installing AVG Anti-Virus Free Edition for Linux (the DEB file is about 93.5 MB), use the Terminal command "sudo avgctl" (without quotes) and reboot your system to ensure that AVG related services (a.k.a. daemons) start properly.

After the system reboot, open the terminal and issue the command "sudo avgupdate" (without quotes) to update the AVG Anti-Virus definition files.

After the update is completed, issue the command "sudo avgscan / -a -H -c" (without quotes) at the terminal to perform a full Anti-Virus scan on your system.

The above command scans all files in your system. The option ‘-a’ instructs the AVG Anti-virus scanner to scan the compressed archive files too. The option ‘-H’ instructs the scanner to use heuristics while scanning. The option ‘-c’ instructs the scanner to scan cookies too.

Reference used: How To Install And Use AVG Antivirus In Linux Mint / Ubuntu


DJ_KIM 13 years ago

I have a Linux with Mint on it. I just installed AVG for Linux on it, and now I can't find it. Any suggestions as to where I might be able to find it on the computer? I can find the folder where it was downloaded to, and I can install it and re-install it, but I can't find it to run it. Please help.

Thanks.

Kim (newbie here)


LONNIEFUTURE 13 years ago

Thanks this will definatly be handy!


bustertech 13 years ago

Thanks for writing this. I'm new to linux and have the goal of learning something about this OS everyday. So far, I love it. It's a challenge when all you've ever done is windows. In some ways it's so much easier than windows and in some ways it's driving me insane. I'll get there though. It's so impressive that my old compac evo N610c was trashable as far as windows OS but with linux, it's got new life and will be a viable product for years. I've bought a wireless card and am going to install another stick of 512MB ram to get a gig but it's running at a respectable rate now for the age of the box. Thanks to everyone out there who write tutorials, reply in chat and work on the apps for making linux. It's the most impressive community I've ever found online.


Alexio 13 years ago

@fuLLcoLLapse - You can read the Sudo Manual Pages.


fuLLcoLLapse 13 years ago

dude, how about the "sudo" and its sub commands?BTW, thank u for this ref.


nurtel9 13 years ago

I like this, thx


nezzbit 13 years ago

thanks big help


bAPTIST 13 years ago

Thank you


wanda 13 years ago

Great thanks.


Firoz_usf 13 years ago

I just want it thanks a lot.


Tonya 13 years ago

Great tutorial! Thank you so much!


gileon 13 years ago

Exactly what I was searching for :)!


gonye 13 years ago

Great summary!


tirebiter 13 years ago

Way cool! Just enough to keep the average user going without overload.


Sol_Badguy 13 years ago

Great tutorial!


hass 13 years ago

very good.


nicu 13 years ago

Thanks, perfect for a beginner like me.


mikefreeman 13 years ago

Awesome! Definitely bookmarking this tutorial!


grim 13 years ago

Amazing tutorial! Helped me a lot, thanks!


akash211 13 years ago

Very good tutorial


efthialex 13 years ago

Very Good job! (y)


zaenal1234 13 years ago

+1


rituraj 13 years ago

Thanks, very helpful...


EDDE_E 13 years ago

Nice!!! Exactly what I was looking for. Excellent reference for the terminal.


itonggant 13 years ago

this is what I need, many thanks...


Russ 13 years ago

Many THANX, again something useful. GR8


Ki3rk3gaard 13 years ago

Ur the Man Alexio ! Kool Beenz home skillet !


m4daredsun 13 years ago

Impressive... I'll keep a printout on my desk.

Thanks Alexio for compiling this list!


aiacomp 13 years ago

Thanks, very helpful.


Edster 14 years ago

I've been looking for this! Thanks Alexio!


Tony 14 years ago

At my age, the whoami command is very useful.


Ki3rk3gaard 14 years ago

This is kool beenz just like high school i've got a cheat sheet ! Thanx Lex


Tony 14 years ago

Very helpful.


Elisa 14 years ago

Cool :-)